package com.mipo.core.utils;

import com.alibaba.fastjson.JSON;
import com.mipo.data.dataService.model.po.SyncConfig;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Map;

/**
 * Created by cc on 2017/11/5.
 */
public class MongoUtils {


    public static String toQueryCondByConfig(Map<String, SyncConfig> configMap) {
        StringBuffer stringBuffer = new StringBuffer();
        for (Map.Entry<String, SyncConfig> entry : configMap.entrySet()) {
            SyncConfig args = entry.getValue();
            stringBuffer.append(",'" + args.getKy() + "':");
            switch (args.getVtp()){
                case 4 :{
                    stringBuffer.append("'"+args.getVal()+"'");
                    break;
                }
                default:{
                    stringBuffer.append( args.getVal() );
                    break;
                }
            }
        }
        if (stringBuffer.length() > 0) {
            return "{" + stringBuffer.substring(1) + "}";
        }
        return "{}";
    }


    public static String toQueryCondByParam(Map<String, Object> paramMap) {
        StringBuffer stringBuffer = new StringBuffer();
        for (Map.Entry<String, Object> entry : paramMap.entrySet()) {
            stringBuffer.append("," + entry.getKey() + ":" + String.valueOf(entry.getValue()));
        }
        if (stringBuffer.length() > 0) {
            return "{" + stringBuffer.substring(1) + "}";
        }
        return "{}";
    }
//
//    public static Object getVal(Map<String, Object> mongoData, String val) {
//        if (val.indexOf(".") > 0) {
//
//            String[] path = val.split("\\.");
//            int keyLevel = 0;
//            Object obj = mongoData;
//            do {
//                if (obj instanceof Map) {
//                    obj = ((Map) obj).get(path[keyLevel]);
//                } else if (obj instanceof List) {
//                    int index = Integer.parseInt(path[keyLevel]);
//                    obj = ((List) obj).get(index);
//                }
//                keyLevel++;
//            } while (keyLevel < path.length);
//            return obj;
//
//        }
//
//
//        Object valObject = mongoData.get(val);
//
//        return valObject;
//    }




}
